new Vue({
  el: '#app',
  data: {
    form: {
      usdtplace: '',
      usdturl: '',
      captcha: '',
    },
    send: false,
    loading: true,
    countDownTime: 60,
    countDownTimer: null,
    rules: rules,
    fileList: [],
  },
  mounted () {
    this.loading = false;
    this.main()
  },
  methods: {
    onClickLeft: function () {
      history.go(-1)
    },
    async main() {
      let user = await $http.get('/api/user/getUserInfo')
      this.user = user.data.data

      this.form.usdtplace = this.user.usdt_place
      this.form.usdturl = this.user.usdt_url
      this.fileList.push({ url: this.user.usdt_url })
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (!valid) { return false; }

        if(!this.fileList.length) {
          this.$toast.fail('请上传二维码')
          return;
        }
        
        let formData = new FormData()
        formData.append('image', this.fileList[0].content)
        $http.upload('/api/user/upload', formData).then(res => {
          let image = res.data.data
          this.form.usdturl = image
          return $http.post('/api/user/upusdt', this.form)
        }).then(res => {
          if (res.data.code != 1) { return this.$toast(res.data.msg) }
          this.$toast.success({
            message: res.data.msg,
            onClose: function () { history.go(-1) }
          })
        })
      })

    },
    async afterRead(files) {
    },
    getCaptcha() {
      if(this.send) { return;}
      this.send = true;
      this.countDownTimer = setInterval(this.countDown, 1000)
    },
    countDown() {
      if(this.countDownTime <= 0) {
        this.send = false
        this.countDownTime = 60
        clearInterval(this.countDownTimer)
      }
      
      this.countDownTime--
    }
  }
})